package com.zpkj.portal.dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.google.gson.internal.LinkedTreeMap;

public class RequestParameter implements Serializable{

	private static final long serialVersionUID = 1L;
	
	private RequestHeader header;
	
	private Object body;

	public RequestHeader getHeader() {
		if(header == null){
			header = new RequestHeader();
		}
		return header;
	}

	public void setHeader(RequestHeader header) {
		this.header = header;
	}

	public Object getBody() {
		return body;
	}

	public void setBody(Object body) {
		this.body = body;
	}
	
	@SuppressWarnings("rawtypes")
	public String getValueFromBody(String key){
		if(body == null){
			return null;
		}
		if(body instanceof LinkedTreeMap){
			Object o = ((LinkedTreeMap)body).get(key);
			if(o != null){
				return String.valueOf(o);
			}else{
				return null;
			}
		}else{
			return null;
		}
	}
	
	@SuppressWarnings("unchecked")
	public List<LinkedTreeMap<String, Object>> getListFromBody(String key){
		if(body == null){
			return new ArrayList<LinkedTreeMap<String, Object>>();
		}
		if(body instanceof LinkedTreeMap){
			Object o = ((LinkedTreeMap<String,Object>)body).get(key);
			if(o instanceof ArrayList){
				return (ArrayList<LinkedTreeMap<String, Object>>)o;
			}else{
				return new ArrayList<LinkedTreeMap<String, Object>>();
			}
		}else{
			return new ArrayList<LinkedTreeMap<String, Object>>();
		}
	}
}
